package com.frxuexi.base.http

import android.content.Context
import androidx.room.Room
import com.frxuexi.base.db.OrderDao
import com.frxuexi.base.db.ParkDatabase
import com.frxuexi.base.db.ShopDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Provides
    @Singleton
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)

    @Provides
    @Singleton
    fun getShopApiService():ShopApiService=RetrofitUtil.retrofitShop.create(ShopApiService::class.java)

    @Provides
    @Singleton
    fun init(@ApplicationContext context: Context):ParkDatabase{
        return Room.databaseBuilder(context,ParkDatabase::class.java,"park2303.db")
            .allowMainThreadQueries()
            .build()
    }

    @Provides
    @Singleton
    fun getShopDao(database: ParkDatabase):ShopDao=database.shopDao()

    @Provides
    @Singleton
    fun getOrderDao(database: ParkDatabase):OrderDao=database.orderDao()
}